//
//  PopViewController.m
//  Mall
//
//  Created by 孙飞燕 on 16/10/21.
//  Copyright © 2016年 孙飞燕. All rights reserved.
//

#import "PopViewController.h"
#import "HomePageViewController.h"
#import "HelpViewController.h"

@interface PopViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    UITableView *_tableVIew;
    NSArray *_imageArr;
    NSArray *_labelArr;

}
@end

@implementation PopViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor orangeColor];
    
    _labelArr = @[@"消息",@"首页",@"帮助",@"我要反馈"];
    _imageArr = @[@"message",@"house",@"note",@"swipe"];

    _tableVIew = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 150, 180)];
    _tableVIew.delegate = self;
    _tableVIew.dataSource = self;
    _tableVIew.scrollEnabled = YES;
    _tableVIew.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_tableVIew];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _imageArr.count;

}


-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *str = @"cellID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:str];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];
    }
    cell.textLabel.text = _labelArr[indexPath.row];
    cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",_imageArr[indexPath.row]]];

    return cell;

}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.row) {
        case 0:
        {

        }
            break;
        case 1:{
            [self dismissViewControllerAnimated:NO completion:^{
                self.viewController.tabBarController.selectedIndex = 0;
                [self.viewController.navigationController popToRootViewControllerAnimated:NO];

            }];

        }
            break;
        case 2:{
            HelpViewController* helpVC = [[HelpViewController alloc] init];
//            [self presentViewController:helpVC animated:NO completion:^{
//
//            }];
            [self dismissViewControllerAnimated:NO completion:^{
                [self.viewController.navigationController pushViewController:helpVC animated:YES];
            }];


        }
            break;
        default:
            break;
    }

}

//重置本控制器的大小
-(CGSize)preferredContentSize{

    if (self.popoverPresentationController != nil) {
        CGSize tempSize ;
        tempSize.height = self.view.frame.size.height;
        tempSize.width  = 155;
        CGSize size = [_tableVIew sizeThatFits:tempSize];  //返回一个完美适应tableView的大小的 size
        return size;
    }else{
        return [super preferredContentSize];
    }
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
